import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:zootix/util/zt_media_util.dart';
import 'package:zootix/zt_app_theme.dart';

class ZtPhotoPickerUtil {
  showPicker({Function? callback}) async {
    return showCupertinoModalPopup(
        context: Get.context!,
        builder: (BuildContext ctx) {
          return CupertinoActionSheet(
            title: const Text('Change avatar'),
            cancelButton: CupertinoActionSheetAction(
                onPressed: () {
                  Get.back();
                },
                child: const Text(
                  'Cancel',
                  style: TextStyle(color: Color(0xffcdcdcd)),
                )),
            actions: ['Photography', 'Album']
                .map((item) => CupertinoActionSheetAction(
                    onPressed: () async {
                      Get.back();
                      XFile? pickedFile = item == 'Photography'
                          ? await ZtMediaUtil().getImageFromCamera()
                          : await ZtMediaUtil().getImageFromGallery();
                      if (pickedFile != null) {
                        if (callback != null) {
                          callback(pickedFile);
                        }
                      }
                    },
                    child: Text(
                      item,
                      style: const TextStyle(color: ZtAppTheme.primaryColor),
                    )))
                .toList(),
          );
        });
  }
}
